package com.tfswx.fljdmxyy.api;

import com.tfswx.fljdmxyy.dto.wjgl.*;
import com.tfswx.fljdmxyy.query.wjgl.WjlbQueryResult;
import com.tfswx.fljdmxyy.service.WjglService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 文件管理
 *
 * @author 唐晓宇
 * @date 2022/10/18
 **/
@Api(tags = "文件管理")
@RestController
@RequestMapping("api/wjgl")
public class WjglController {

    @Resource
    private WjglService wjglService;

    @ApiOperation(value = "下载文件")
    @RequestMapping(value = "/download", method = {RequestMethod.POST, RequestMethod.GET})
    public void download(@Validated WjDownloadInputDTO dto, HttpServletResponse response) {
        wjglService.download(dto, response);
    }

    @ApiOperation(value = "上传文件", notes = "上传文件", httpMethod = "POST")
    @PostMapping("/upload")
    public Boolean download(@Validated WjUploadInputDTO dto) {
        return wjglService.upload(dto);
    }

    @ApiOperation(value = "查询文件树", notes = "查询文件树", httpMethod = "POST")
    @PostMapping("/queryWjlb")
    public List<WjlbQueryResult> queryWjlb() {
        return wjglService.queryWjlb();
    }

    @ApiOperation(value = "创建文件夹", notes = "创建文件夹", httpMethod = "POST")
    @PostMapping("/addWjj")
    public Boolean addWjj(@RequestBody @Validated WjjAddInputDTO dto) {
        return wjglService.addWjj(dto);
    }

    @ApiOperation(value = "修改文件信息", notes = "修改文件信息", httpMethod = "POST")
    @PostMapping("/updateWj")
    public Boolean updateWj(@RequestBody @Validated WjUpdateInputDTO dto) {
        return wjglService.updateWj(dto);
    }

    @ApiOperation(value = "删除文件", notes = "删除文件", httpMethod = "POST")
    @PostMapping("/deleteWj")
    public Boolean deleteWj(@RequestBody @Validated WjDeleteInputDTO dto) {
        return wjglService.deleteWj(dto);
    }
}
